package com.fire.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.fire.definedAnnotation.Authorization;
import com.fire.service.CommonService;
import com.fire.util.MsgInfo;
import com.fire.util.base.ResultBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/common")
@Api(description = "公共模块API")
@CrossOrigin
public class CommonController {

	@Autowired
	private CommonService commonService;

	/**
	 * 统一图片上传接口
	 * 
	 * @param files
	 * @param request
	 * @param response
	 * @return
	 */
	@ApiOperation(value = "单图片上传", notes = "供应商通过此API进行图片上传")
	@ApiImplicitParam(name = "图片入参", value = "image", required = true, dataType = "MultipartFile")
	@Authorization
	@RequestMapping(value = "/imageUpload.do", method = RequestMethod.POST)
	public ResultBody fileUpload(@RequestParam("image") MultipartFile image, HttpServletRequest request,
			HttpServletResponse response) {
		ResultBody result = null;
		try {
			result = commonService.imageUpload(image);
		} catch (Exception e) {
			result = ResultBody.goBack(MsgInfo.z_error_code, MsgInfo.z_error_msg);
			e.printStackTrace();
			return result;
		}
		return result;
	}

}
